use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// 添加新项目
    Add {
        /// 项目名称
        #[arg(short='n', long)]
        name: String,

        #[arg(short='g', long="te")]
        name1: String,

        /// 可选的项目描述
        #[arg(short, long)]
        description: Option<String>,
    },

    /// 完成项目
    Complete {
        /// 项目ID
        #[arg(short, long)]
        id: u32,
    },

    /// 列出所有项目
    List {
        /// 只显示未完成的项目
        #[arg(short, long)]
        pending: bool,
    },
}

//   cargo run  list  -p
fn main() {
    let fhj = format!("{}", 30);
    println!("{}", fhj);
    let cli = Cli::parse();

    match &cli.command {
        Commands::Add { name,name1, description } => {
            println!("添加项目: {}, 描述: {:?},{}", name, description, name1);
            // 这里添加实际的项目添加逻辑
        }
        Commands::Complete { id } => {
            println!("完成项目 ID: {}", id);
            // 这里添加实际的完成项目逻辑
        }
        Commands::List { pending } => {
            if *pending {
                println!("列出未完成的项目");
            } else {
                println!("列出所有项目");
            }
            // 这里添加实际的列表逻辑
        }
    }
}


/****
use std::ops::RangeInclusive;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    /// Network port to use
    #[arg(short, long, value_parser = port_in_range)]
    port: u16,
}

const PORT_RANGE: RangeInclusive<usize> = 1..=65535;
 
fn port_in_range(s: &str) -> Result<u16, String> {
    let port: usize = s
        .parse()
        .map_err(|_| format!("`{s}` isn't a port number"))?;
    if PORT_RANGE.contains(&port) {
        Ok(port as u16)
    } else {
        Err(format!(
            "port not in range {}-{}",
            PORT_RANGE.start(),
            PORT_RANGE.end()
        ))
    }
}

fn main() {
    println!("Hello, world!");
    let cli = Cli::parse();
 
    println!("PORT = {}", cli.port);
}
***/
